/*
 * @Author: shiguo
 * @Date: 2022-05-05 15:56:21
 * @LastEditors: shiguo
 * @LastEditTime: 2023-01-03 17:02:57
 * @FilePath: /@aks-dev/easyui/lib/Echarts/helper.tsx
 */


export const getHtml = (props: { backgroundColor: any }) => {
    return `
      <!DOCTYPE html>
        <html>
    
        <head>
          <title>echarts</title>
          <meta http-equiv="content-type" content="text/html; charset=utf-8">
          <!-- webView ios适配 start -->
          <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
          <!-- webView ios适配 end -->
          <style type="text/css">
            html,
            body {
              height: 100%;
              width: 100%;
              margin: 0;
              padding: 0;
              background-color: rgba(0, 0, 0, 0);
            }
    
            #main {
              height: 100%;
              background-color: rgba(0, 0, 0, 0);
            }
    
          </style>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.1/echarts.min.js"></script>
        </head>
    
        <body style="background-color:${props.backgroundColor}">
          <div id="main"></div>
        </body>
    
      </html>
      `
  }

  /**
   * https://res.actiiot.com/echarts/5.0.2/echarts.min.js
   * 
   * https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.1/echarts.min.js
   */
  
  export const toString = (obj: object) => {
    let result = JSON.stringify(obj, function (key, val) {
      // 对function进行特殊处理
      if (typeof val === 'function') {
        return `~ha~${val}~ha~`;
      }
      return val;
    });
    // 再进行还原
    do {
      result = result.replace('\"~ha~', '').replace('~ha~\"', '').replace(/\\\"/g, "\"");//最后一个replace将release模式中莫名生成的\"转换成"
    } while (result.indexOf('~ha~') >= 0);
  
    return result;
  }
  

  ///.replace(/\\n/g, '')